package org.power.bus.controller;

import io.swagger.annotations.ApiOperation;
import org.power.bus.model.Current;
import org.power.bus.model.Feature;
import org.power.bus.model.Temperature;
import org.power.bus.service.PowerService;
import org.power.core.common.DisplayResult;
import org.power.core.util.XlsxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/v2")
public class DisplayController {
    @Autowired
    private PowerService powerService;

    @ApiOperation(value = "数据量")
    @GetMapping("/count")
    public Map getCount() {
        Map<String, Integer> countMap = powerService.getCount();
        return DisplayResult.success(countMap);
    }

    @ApiOperation(value = "预览温度表")
    @GetMapping("/previewEnvironmentTable")
    public Map previewEnvironmentTable() {
        List<Temperature> temperatureList = powerService.previewEnvironmentTable();
        return DisplayResult.success(temperatureList);
    }

    @ApiOperation(value = "预览电流表")
    @GetMapping("/previewCurrentTable")
    public Map previewCurrentTable() {
        List<Current> currentList = powerService.previewCurrentTable();
        return DisplayResult.success(currentList);
    }

    @ApiOperation(value = "当日数据流入")
    @GetMapping("/getTodayTemperature")
    public Map getTodayTemperature() {
        List<Feature> featureList = powerService.getTodayTemperature();
        return DisplayResult.success(featureList);
    }

    @ApiOperation(value = "皮尔逊系数")
    @GetMapping("/getPearsonParam")
    public Map getPearsonParam() {
        Map<String, String> pearsonParamMap = powerService.getPearsonParam();
        return DisplayResult.success(pearsonParamMap);
    }

    @ApiOperation(value = "top排名")
    @GetMapping("/getTemperatureTop")
    public Map getTemperatureTop() {
        Map<String, Object> temperatureTopMap = powerService.getTemperatureTop();
        return DisplayResult.success(temperatureTopMap);
    }

    @ApiOperation(value = "折线图")
    @GetMapping("/getCurrentCompare")
    public Map getCurrentCompare() throws Exception {
        List list = powerService.getCurrentCompare();

        /*String count = "0";
        String truePath = "static/data/预测结果/TRUE.xlsx";
        String gruPath = "static/data/预测结果/GRU.xlsx";
        String lstmPath = "static/data/预测结果/LSTM.xlsx";

        List list = new ArrayList();
        list.add(XlsxUtil.getPre2(truePath, Integer.parseInt(count)));
        list.add(XlsxUtil.getPre2(lstmPath, Integer.parseInt(count)));
        list.add(XlsxUtil.getPre2(gruPath, Integer.parseInt(count)));

        List timeList = new ArrayList();
        int num = Integer.parseInt(count);
        for (int i = 1; i <= 24; i++) {
            timeList.add(getTime(num + i));
        }
        list.add(timeList);*/
        return DisplayResult.success(list);
    }

    public String getTime(int count) {
        int day = count / (2 * 24) + 1;
        int hour = (count % (2 * 24)) / 2;
        int second = count % 2;
        System.out.print(day + ":" + hour + ":" + second * 30 + "  ");
        return "9/" + day + " " + hour + ":" + second * 30;
    }
}
